<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="primus" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="fn" tagdir="/WEB-INF/tags/form" %>
<primus:page title="订单管理">
    <jsp:attribute name="css">
        <style type="text/css">
            #table .operate {
                min-width: 80px;
            }
        </style>
    </jsp:attribute>
    <jsp:attribute name="script">
        <script type="application/javascript">
            $(function () {
                $("#table").DataTable({
                    "lengthMenu": [[10, 20, 50, -1], [10, 20, 50, "所有"]],
                    "columnDefs": [{"targets": [7], "orderable": false}],
                    "searching": false,
                    "order": [[0, "asc"]]
                });
            });
            $("body").on("click", ".geo-line", function () {
                var id = $(this).data("id");
            })
        </script>
    </jsp:attribute>
    <jsp:body>
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="welcome.do">
                        首页
                    </a>
                </li>
                <li>
                    <a href="geo/provinces">
                        实例管理
                    </a>
                </li>
                <li class="active">
                    订单管理
                </li>
            </ul>
        </div>

        <!-- 模态框 -->
        <div class="modal fade" style="width: 100%; height: 100%;" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content" style="width: 100%; height: 100%; display: inline-table;">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">订单详情</h4>
                    </div>
                    <div class="modal-body" style="width: 880PX; height: 400PX; display: inline-table;">
                        <div style="width: 100%; height: 100%; display: inline-table;">
                            <div class="tabbable" style="width: 100%; height: 100%; display: inline-table;">
                                <ul class="nav nav-tabs padding-12 tab-color-blue background-blue" id="myTab4">
                                    <li class="">
                                        <a id="li1" data-toggle="tab" href="#ord_bas_inf" aria-expanded="false">订单基本信息</a>
                                    </li>

                                    <li class="">
                                        <a data-toggle="tab" href="#pro_inf" aria-expanded="false">商品信息</a>
                                    </li>

                                    <li class="active">
                                        <a data-toggle="tab" href="#pro_spl_inf" aria-expanded="true">商品拆分信息</a>
                                    </li>

                                    <li class="active">
                                        <a data-toggle="tab" href="#pre_inf" aria-expanded="true">优惠信息</a>
                                    </li>

                                    <li class="active">
                                        <a data-toggle="tab" href="#pay_inf" aria-expanded="true">支付信息</a>
                                    </li>

                                    <li class="active">
                                        <a data-toggle="tab" href="#con_inf" aria-expanded="true">收货人信息</a>
                                    </li>

                                    <li class="active">
                                        <a data-toggle="tab" href="#mem_inf" aria-expanded="true">会员信息</a>
                                    </li>
                                </ul>

                                <div class="tab-content">
                                    <div id="ord_bas_inf" class="tab-pane">
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >订单来源</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >商品总金额</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >会员帐号</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                        <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >订单编号</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >商品优惠金额</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >会员姓名</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >下单时间</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >订单优惠金额</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >会员手机号</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >配送优先级</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >平台优惠金额</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >会员等级</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >配送门店</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >配送费用</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >收货人姓名</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >门店名称</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >订单总金额</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >收货人电话</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >配送方式</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >已支付金额</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >收货人地址</label>
                                                <textarea class="col-xs-6 col-sm-6" rows="3"></textarea>
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >要求送达时间</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >下单人</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >进入中台时间</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >下单人工号</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >用户备注</label>
                                                <textarea rows="3" cols="100"></textarea>
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >卖家备注</label>
                                                <textarea rows="3" cols="100"></textarea>
                                            </div>
                                        </div>
                                    </div>

                                    <%--商品信息--%>
                                    <div id="pro_inf" class="tab-pane">
                                        <table id="table_pro_inf" class="table table-hover" style="width: 100%;">
                                            <thead>
                                            <tr>
                                                <th>商品编号</th>
                                                <th>商品名称</th>
                                                <th>商品数量</th>
                                                <th>商品总价</th>
                                                <th>市场价</th>
                                                <th>购买价</th>
                                                <th>商品类型</th>
                                            </tr>
                                            </thead>
                                        </table>
                                    </div>

                                    <%--商品拆分信息--%>
                                    <div id="pro_spl_inf" class="tab-pane">
                                        <table id="table_pro_spl_inf" class="table table-hover" style="width: 100%;">
                                            <thead>
                                            <tr>
                                                <th>组合商品编号</th>
                                                <th>商品编号</th>
                                                <th>商品名称</th>
                                                <th>商品数量</th>
                                                <th>市场价</th>
                                                <th>购买价</th>
                                            </tr>
                                            </thead>
                                        </table>
                                    </div>

                                    <%--商品优惠信息--%>
                                    <div id="pre_inf" class="tab-pane">
                                        <table id="table_pre_inf" class="table table-hover" style="width: 100%;">
                                            <thead>
                                            <tr>
                                                <th>优惠ID</th>
                                                <th>优惠信息名称</th>
                                                <th>优惠活动描述</th>
                                                <th>优惠金额</th>
                                            </tr>
                                            </thead>
                                        </table>
                                    </div>

                                    <div id="pay_inf" class="tab-pane">
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >付款方式</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >支付状态</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >已付金额</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >未付金额</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                    </div>

                                    <div id="con_inf" class="tab-pane">
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >收货人姓名</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >手机号</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >邮箱</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >省</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >市</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >县/区</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >详细地址</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >经度</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >纬度</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                    </div>

                                    <div id="mem_inf" class="tab-pane">
                                        <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >会员帐号</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >会员电话</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >会员姓名</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                        <br>
                                         <div class="row">
                                            <div class="col-sm-4">
                                                <label class="col-sm-6 control-label no-padding-right" >会员级别</label>
                                                <input type="text" class="col-xs-6 col-sm-6" />
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="page-content">

            <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->
                    <div class="row">
                        <div class="col-xs-12">
                            <h3 class="header smaller lighter blue">
                                订单管理
                            </h3>
                            <div class="row">

                                <div class="form-group row">
                                    <label class="col-sm-1 control-label no-padding-right">订单状态</label>
                                    <div class="col-sm-3">
                                        <select id="orderSele">
                                            <option value="WAIT_PAY">代付款</option>
                                            <option value="CANCELED">已取消</option>
                                        </select>
                                    </div>
                                    <label class="col-sm-1 control-label no-padding-right">订单编号</label>
                                    <div class="col-sm-3">
                                        <input type="text" class="col-xs-12 col-sm-12" placeholder="订单编号" id="orderInput">
                                    </div>
                                    <button type="button" class="btn btn-warning ace-icon fa fa-search btn-sm" id="searchButton">
                                        搜索
                                    </button>
                                    <!-- 模态框点击按钮 -->
                                    <button type="button" class="btn btn-danger ace-icon fa fa-warning btn-sm" id="detailButton">
                                        详情
                                    </button>
                                    <button type="button" class="btn btn-inverse ace-icon fa fa-refresh btn-sm" id="refreshButton">
                                        重置
                                    </button>
                                </div>
                            </div>
                        </div>

                            <div class="row">
                                <table id="table" class="table table-bordered table-striped"
                                       style="width: 100%;">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script>
            $(function(){
                // 初始化加载
                var table = first("WAIT_PAY", "");

                var sele = $("#orderSele").val();
                var inpu = $("#orderInput").val();


                //关闭datatable弹窗提示
                $.fn.dataTable.ext.errMode = 'none'; //不显示任何错误信息

                // 选择行
                $('#table tbody').on('click', 'tr', function () {
                    if ($(this).hasClass('selected')) {
                        if ($(this).hasClass('odd')) {
                            $(this).css({'background-color': '#f9f9f9'})
                        } else {
                            $(this).css({'background-color': '#ffffff'})
                        }
                        $(this).removeClass('selected');
                    } else {
                        if ($("#table").dataTable().$('tr.selected').hasClass('odd')) {
                            $("#table").dataTable().$('tr.selected').css({'background-color': '#f9f9f9'})
                        } else {
                            $("#table").dataTable().$('tr.selected').css({'background-color': '#ffffff'})
                        }
                        $("#table").dataTable().$('tr.selected').removeClass('selected');
                        $(this).addClass('selected');
                        $(this).css({'background-color': '#00c0ef'})
                    }
                });
            });

            // 订单编码检验
            $("#orderInput").blur(function(){
                var inpu = $("#orderInput").val();
                if (inpu != "") {
                    if (inpu.length > 65){
                        layer.msg("对不起，订单编码长度不可超过65")
                    }
                }
            });

            // 订单搜索
            $("#searchButton").on("click", function () {
                var sele = $("#orderSele").val();
                var inpu = $("#orderInput").val();

                dttable.api().fnClearTable(); //清空一下table
                dttable.api().fnDestroy(); //还原初始化了的datatable
                first(sele, inpu);
            });

            // 查看详情
            $("#detailButton").on("click", function () {
                if ($('.selected').text() == "") {
                    layer.msg("对不起，请选择一行数据")
                } else {
                    var nTrs = $("#table").dataTable().fnGetNodes();//fnGetNodes获取表格所有行，nTrs[i]表示第i行tr对象
                    var row1;
                    for(var i = 0; i < nTrs.length; i++){
                        if($(nTrs[i]).hasClass('selected')){
                            row1 = $("#table").dataTable().fnGetData(nTrs[i]);
                        }
                    }

//                    window.location.href="/order/details.jsp?row="+row1;
                    sessionStorage.setItem('orderDetails', JSON.stringify(row1)); // 存入一个值

                    window.location.href="/order/details";

//                    $("#myModal").modal({show:true});   // 打开模态框

//                    $("#li1").click();
//
//                    $("#table_pro_inf").dataTable({
//                        searching: false,
//                        ordering: false,
//                        paging: false, // 禁止分页
//                        data:row1.pro_inf
//                    });
//                    $("#table_pro_spl_inf").dataTable({
//                        searching: false,
//                        ordering: false,
//                        paging: false, // 禁止分页
//                        data:row1.pro_spl_inf
//                    });
//                    $("#table_pre_inf").dataTable({
//                        searching: false,
//                        ordering: false,
//                        paging: false, // 禁止分页
//                        data:row1.pre_inf
//                    });
                }

            });

            // 重置按钮
            $("#refreshButton").on("click", function () {
                $("#orderSele").val("WAIT_PAY");
                $("#orderInput").val("");
                $('#table').dataTable().api().ajax.reload(null, false);
            })

            // 表格加载
            function first(sele, inpu) {
                $("#table").dataTable({
                    searching: false,
                    ordering: false,
                    lengthMenu: [10, 20, 50],
                    ajax: {
                    url: '/order/list',
                        type: 'GET',
                        dataType: "json",
                        data: {
                        "state": sele,
                        "orderCode": inpu
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                    }
                },
                    columns: [
                        {
                            "title": "订单来源",
                            "data": "client"
                        },
                        {
                            "title": "订单编号",
                            "data": "orderCode"
                        },
                        {
                            "title": "订单优先级",
                            "data": "roomCode"
                        },
                        {
                            "title": "订单创建时间",
                            "data": "changed"
                        },
                        {
                            "title": "要求送达时间",
                            "data": "time"
                        },
                        {
                            "title": "支付方式",
                            "data": "paymentWay"
                        },
                        {
                            "title": "支付状态",
                            "data": "paymentState"
                        },
                        {
                            "title": "订单金额",
                            "data": "warId"
                        },
                        {
                            "title": "订单状态",
                            "data": "state"
                        }
                    ],
                    columnDefs: [
                        {
                            "targets": [0],
                            "defaultContent": "",
                            "class": "text-center nowrap",
                            "render": function (data, type, row) {
                                if (data != undefined) {
                                    return clientFormmater(data);
                                }
                            }
                        },
                        {
                            "targets": [1],
                            "defaultContent": "",
                            "class": "text-center nowrap"
                        },
                        {
                            "targets": [2],
                            "defaultContent": "",
                            "class": "text-center nowrap"
                        },
                        {
                            "targets": [3],
                            "defaultContent": "",
                            "class": "text-center nowrap"
                        },
                        {
                            "targets": [4],
                            "defaultContent": "",
                            "class": "text-center nowrap"
                        },
                        {
                            "targets": [5],
                            "defaultContent": "",
                            "class": "text-center nowrap",
                            "render": function (data, type, row) {
                                if (data != undefined) {
                                    return paymentWayFormmater(data);
                                }
                            }
                        },
                        {
                            "targets": [6],
                            "defaultContent": "",
                            "class": "text-center nowrap",
                            "render": function (data, type, row) {
                                if (data != undefined) {
                                    return paymentStateFormmater(data);
                                }
                            }
                        },
                        {
                            "targets": [7],
                            "defaultContent": "",
                            "class": "text-center nowrap",
                        },
                        {
                            "targets": [8],
                            "defaultContent": "",
                            "class": "text-center nowrap",
                            "render": function (data, type, row) {
                                if (data != undefined) {
                                    return stateFormmater(data);
                                }
                            }
                        }
                    ]
                });
            }


            // 订单状态格式化
            function stateFormmater(data) {
                if ("WAIT_PAY" == data) {
                    return "待付款";
                } else if ("WAIT_SEND" == data) {
                    return "待发货";
                } else if ("WAIT_RECEIVE" == data) {
                    return "待收货";
                } else if ("WAIT_EVALUATION" == data) {
                    return "待评价";
                } else if ("FINISHED" == data) {
                    return "订单完成";
                } else if ("CANCELED" == data) {
                    return "已取消";
                } else if ("AFTER_SALE" == data) {
                    return "售后中";
                } else if ("FINISHED_AFTER_SALE" == data) {
                    return "售后完成";
                }
            }

            // 支付状态格式化
            function paymentStateFormmater(data) {
                if ("WAIT_PAY" == data) {
                    return "待付款";
                } else if ("PAY_SUCCESS" == data) {
                    return "付款成功";
                } else if ("PAY_FAILURE" == data) {
                    return "付款失败";
                } else if ("PAY_ON_DELIVERY" == data) {
                    return "货到付款";
                }
            }

            // 支付方式格式化
            function paymentWayFormmater(data) {
                if ("alipay" == data) {
                    return "支付宝支付";
                } else if ("wechatpay" == data) {
                    return "微信钱包支付";
                } else if ("cod" == data) {
                    return "货到付款";
                } else if ("balance" == data) {
                    return "电子钱包支付";
                } else if ("unionpay" == data) {
                    return "银联支付";
                } else if ("winepay" == data) {
                    return "储值卡支付";
                } else if ("whitebar" == data) {
                    return "白条支付";
                } else if ("swiftpay" == data) {
                    return "威富通支付";
                }
            }

            // 订单来源格式化
            function clientFormmater(data) {
                if ("android" == data) {
                    return "安卓";
                } else if ("wechat" == data) {
                    return "微商城";
                }
            }

        </script>
    </jsp:body>
</primus:page>